package com.xintonghua.bussiness.adapter;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xintonghua.base.adapter.BaseAdapter;
import com.xintonghua.base.utils.MyUtils;
import com.xintonghua.bussiness.BuildConfig;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.bean.StaffManagerBean;
import com.xintonghua.bussiness.ui.user.manage.EmployeeInfoActivity;
import com.xintonghua.bussiness.ui.user.manage.TaskSetActivity;
import com.xintonghua.bussiness.util.GlideUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：wanxianyi
 * 时间：2018/1/13.
 * 包名：com.xintonghua.hongyi.adapter
 */

public class EmployeeAdapter extends BaseAdapter<StaffManagerBean, EmployeeAdapter.EmployeeViewHolder> {
    private int type = 0;

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public EmployeeAdapter(Activity mActivity, List<StaffManagerBean> list) {
        super(mActivity, list);
    }

    @Override
    public EmployeeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.adapter_employee, parent, false);
        return new EmployeeViewHolder(view);
    }

    @Override
    public void onBindViewHolder(EmployeeViewHolder holder, int position) {
        final StaffManagerBean bean = list.get(position);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.height = MyUtils.getWidth(mActivity) / 2 - MyUtils.dip2px(mActivity, 24);
        holder.ivStaffHead.setLayoutParams(params);
        GlideUtils.load(mActivity, holder.ivStaffHead, bean.getImg(), R.drawable.icon_goods);
        holder.tvManageName.setText(bean.getUserName());
        holder.tvStaffType.setText(bean.getPositionName());
        holder.ivCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MyUtils.callDial(mActivity, bean.getPhone());
            }
        });
        if (type == 1) { //任务管理 选择员工
            holder.ivStaffHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle = new Bundle();
                    bundle.putParcelable(BuildConfig.FLAVOR, bean);
                    MyUtils.openActivity(mActivity, TaskSetActivity.class, bundle);
                }
            });
        } else if (type == 2) { //门店管理 员工管理
            holder.ivStaffHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle = new Bundle();
                    bundle.putParcelable(BuildConfig.FLAVOR, bean);
                    MyUtils.openActivity(mActivity, EmployeeInfoActivity.class, bundle);
                }
            });

        }

    }

    class EmployeeViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_staff_head)
        ImageView ivStaffHead;
        @BindView(R.id.tv_manage_name)
        TextView tvManageName;
        @BindView(R.id.tv_staff_type)
        TextView tvStaffType;
        @BindView(R.id.iv_call)
        ImageView ivCall;

        public EmployeeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
